<?php
require_once dirname(__FILE__) . '/../../../incls/php/dbutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/miscutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/config.php';
session_name(SESSION);
session_start();

$myPdo = DbUtils::createPdoInst();
$page_id = MiscUtils::getParam('i', 0);

$SIZE = 10;
$page = MiscUtils::getParam('pg', 1);
$order = MiscUtils::getParam('o', 't.sold__');
$queue = MiscUtils::getParam('q', 'DESC');
$cond_vals = new stdClass(); 
$cond_vals->c = 't.status = :v1';
$cond_vals->v = array(':v1' => 1);
$opt = new stdClass();
$opt->select_expr = 'id, track_id, date, enabled_stock, enabled_delivery, enabled_member_price, brand_id, category_id, name, price, stock, stock_alert, intro, status, alert__';
$items = DbUtils::get($myPdo, TABLE_NAME_PREFIX_PLUGIN . 'ecom_product', $cond_vals, $order, $queue, $page, $SIZE, $opt)->d;
foreach ($items as $item) {
  $item->_img = 'images/no_image.gif';
  $cond_vals = new stdClass(); 
  $cond_vals->c = 't.product_track_id = :v1 AND is_default = 0';
  $cond_vals->v = array(':v1' => $item->track_id);
  $tmp = DbUtils::get($myPdo, TABLE_NAME_PREFIX_PLUGIN . 'ecom_product_img', $cond_vals, NULL, NULL, NULL, NULL, NULL)->d;
  if (count($tmp) > 0) {
    if (file_exists($tmp[0]->file)) {
      $item->_img = $tmp[0]->file;
    }
    
  }
  
  $item->_prc = $item->price;
  if (isset($_SESSION['index' . USER]) && $_SESSION['index' . USER]->id) {
    $cond_vals = new stdClass();
    $cond_vals->c = 't.product_track_id = :v1 AND t.member_id = :v2';
    $cond_vals->v = array(':v1' => $item->track_id, ':v2' => $_SESSION['index' . USER]->member_id);
    $tmp = DbUtils::get($myPdo,  TABLE_NAME_PREFIX_PLUGIN . 'ecom_product_member_price', $cond_vals, NULL, NULL, NULL, NULL, NULL)->d;
    if (count($tmp) > 0) {
      $item->_prc = $tmp[0]->price;
    }
  }
}?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/javascript" src="../../../libs/jquery/jquery-1.6.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="carousel/css/style.css" media="screen" />
<!-- ANIMATE AND EASING LIBRARIES -->
<script type="text/javascript" src="carousel/services-plugin/js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="carousel/services-plugin/js/jquery.cssAnimate.mini.js"></script>
<!-- TOUCH AND MOUSE WHEEL SETTINGS -->
<script type="text/javascript" src="carousel/services-plugin/js/jquery.touchwipe.min.js"></script>
<script type="text/javascript" src="carousel/services-plugin/js/jquery.mousewheel.min.js"></script>
<!-- jQuery SERVICES Slider  -->
<script type="text/javascript" src="carousel/services-plugin/js/jquery.themepunch.services.min.js"></script>
<link rel="stylesheet" type="text/css" href="carousel/services-plugin/css/settings.css" media="screen" />
<style>
.bg {
  background: url(images/left.gif) no-repeat;
  text-align: left;
  padding-left: 50px;
}
.bg2 {
  background: url(images/bg.gif) repeat-x;
  padding-top: 20px;
}
.bg3 {
  background: url(images/bg2.gif) 0% 180px repeat-x;
  height: 300px;
}
.my_title {
  font-family: Lucida Sans Unicode;
  font-weight: bold;
  margin-left: 10px;
  margin-bottom: 15px;
  font-size: 14px;
}
.my_name {
  font-family: Lucida Sans Unicode;
  font-weight: bold;
}
.my_price {
  font-family: Lucida Sans Unicode;
}
</style>
</head>
<body>
<div class="bg3">
  <div class="bg">
    <div class="bg2">
      <div class="my_title">Most Popular</div>
      <div class="example-wrapper" style="margin-right: auto;">
          <div id="services-example-1" class="theme1">
            <ul>
              <?php foreach ($items as &$item) { ?>
              <li style="text-align: center;cursor: pointer;" onclick="window.open('<?php echo 'http://' . URL . '?i=' . HOME_PROD_ID . "&id=$item->track_id"; ?>');">
                <div class="my_name"><?php echo $item->name; ?></div>
                <img style="width: 130px;height: 120px;" class="thumb" src="<?php echo $item->_img; ?>" data-bw="images/services/service1_bw.jpg">
                <div class="my_price">$<?php echo $item->_prc; ?></div>
              </li>
              <?php } ?>
            </ul>
    
            <!--  ###############   - TOOLBAR (LEFT/RIGHT) BUTTONS  - ###############  -->
            <div class="toolbar">
              <div class="left"></div><div class="right"></div>
            </div>
          </div>
      </div>
    </div>
  <div>
</div>
<script type="text/javascript">
var tpj=jQuery;
tpj.noConflict();
tpj(document).ready(function() {
  if (tpj.fn.cssOriginal!=undefined) {
    tpj.fn.css = tpj.fn.cssOriginal;
    tpj('#services-example-1').services({
      width:590,
      height:180,
      slideAmount:4,
      slideSpacing:5,
      carousel:"off",
      touchenabled:"on",
      mouseWheel:"on",
      hoverAlpha:"off",     // Turns Alpha Fade on/off by Hovering
      slideshow:0,        // 0 = No SlideShow, 1000 = 1 sec Slideshow (rotating automatically)
      hovereffect:"off",     // All Hovereffect on/off
      callBack:function() { }   //Callback any Function after loaded
    });
  }
});
</script>
</body>
</html>
